#version 330 core

in vec3 aPos;
in vec3 aNormal;
in vec3 aColor;

out vec4 fragColor;

vec3 lightColor = vec3(1.0, 1.0, 1.0);

vec3 viewPos = vec3(0.0, 0.0, 3.0);

uniform vec3 lightPos;

void main() {
    float ambientStrength = 0.1;
    vec3 ambient = ambientStrength * lightColor;

    vec3 norm = normalize(aNormal);
    vec3 lightDir = normalize(lightPos - aPos);

    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = diff * lightColor;

    float specularStrength = 0.7;
    vec3 viewDir = normalize(viewPos - aPos);
    vec3 reflectDir = reflect(-lightDir, norm);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
    vec3 specular = specularStrength * spec * lightColor;  

    vec3 combine = (ambient + diffuse + specular) * aColor;
    fragColor = vec4(combine, 1.0);
}